import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:random_lottery_ticket/dbutil.dart';
import 'package:random_lottery_ticket/lottery.dart';
import 'package:random_lottery_ticket/random.dart';
import 'package:random_lottery_ticket/records.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Index extends StatefulWidget {
  Index({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index> {
  int _currentIndex = 0;
  final List<Widget> _childrenPages = [
    new Random(),
    new Lottery(),
    new Records()
  ];


  @override
  void initState() {
    DBUtil().init();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: Size(1080, 2340));
    return Scaffold(
      resizeToAvoidBottomPadding:false,
      appBar: AppBar(
        title: Text(widget.title),
        centerTitle: true,
      ),
      bottomNavigationBar: BottomAppBar(
        notchMargin: 1,
        color: Colors.red,
        shape: AutomaticNotchedShape(
            RoundedRectangleBorder(), StadiumBorder(side: BorderSide())),
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            IconButton(
              tooltip: "开奖公告",
              color: Colors.white,
              icon: Icon(Icons.stars_rounded),
              onPressed: () {
                setState(() {
                  _currentIndex = 1;
                });

                print('开奖公告');
              },
            ),
            IconButton(
              tooltip: "我的记录",
              color: Colors.white,
              icon: Icon(Icons.receipt_rounded),
              onPressed: () {
                setState(() {
                  _currentIndex = 2;
                });
                print('我的记录');
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _currentIndex = 0;
          });
          print('随机');
        },
        child: const Text("随机"),
      ),
      floatingActionButtonLocation:
          FloatingActionButtonLocation.miniCenterDocked,
      body: Center(
        child: _childrenPages[_currentIndex],
      ),
    );
  }
}
